package com.hzf.booklibrary.biz;

import com.hzf.booklibrary.ReaderApplication;
import com.hzf.booklibrary.bean.Recommend;
import com.hzf.booklibrary.utils.FileUtils;
import com.hzf.booklibrary.utils.LogUtils;
import com.hzf.ftp.DownloadListener;
import com.hzf.ftp.FtpUtils;


import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2017/5/18.
 */

public class FTPFileLoader {
    private String server;
    private int port;
    private String userName;
    private String pwd;
    private DownloadListener mListener;

    public FTPFileLoader(String server, int port, String userName, String pwd, DownloadListener mListener) {
        this.server = server;
        this.port = port;
        this.userName = userName;
        this.pwd = pwd;
        this.mListener = mListener;
    }
    public  void downloadFile(Recommend.RecommendBooks book){
        Map<String,String> paths = new HashMap<>();
        paths.put("server",book.path);
        paths.put("local", FileUtils.getTxtPath(book.id,book.chaptersCount));
        new DownloadThread(paths).start();
    }
    private  class DownloadThread extends Thread {
        private Map<String ,String> paths;

        public DownloadThread(Map<String, String> paths) {
            this.paths = paths;
        }
        @Override
        public void run() {
            FtpUtils ftp =  new FtpUtils("192.168.1.193",21,"zjc","123456");
            ftp.setDownloadListener(mListener);
            ftp.connectServer();
            ftp.downloadFile("/image/111.txt", String.valueOf(ReaderApplication.getsInstance().getCacheDir())+"/1.txt");
            LogUtils.e( String.valueOf(ReaderApplication.getsInstance().getCacheDir())+" /1.txt");
            ftp.closeServer();
        }
    }
}
